package com.erp.erp_servers.RoleGroupMember.imp;

import com.erp.erp_dao.RoleGroupMember.IRoleGroupMemberDAO;
import com.erp.erp_entitys.RoleGroupMember.RoleGroupMemberEntity;
import com.erp.erp_entitys.RoleGroupMember.RoleGroupMemberEntityExample;
import com.erp.erp_servers.RoleGroupMember.IRoleGroupMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ImpRoleGroupMemberService
 * @Description 角色组成员列表实现类
 * @Author songjizhen
 * @Date 2020-07-04 11:52
 * @Version 1.0
 */
@Service
public class ImpRoleGroupMemberService implements IRoleGroupMemberService {
    @Autowired
    IRoleGroupMemberDAO roleGroupMemberDAO;
    /**
     * 新增角色组成员
     *
     * @param record
     * @return
     */
    @Override
    public int insertSelective(RoleGroupMemberEntity record) {
        return roleGroupMemberDAO.insertSelective(record);
    }

    /**
     * 删除角色组成员
     *
     * @param record
     * @return
     */
    @Override
    public int deleteByExample(RoleGroupMemberEntity record) {

        return roleGroupMemberDAO.deleteByExample(this.getExamle(record));
    }

    @Override
    public int deleteByExample(RoleGroupMemberEntityExample example) {
        return roleGroupMemberDAO.deleteByExample(example);
    }

    /**
     * 根据条件获取角色组成员列表
     *
     * @param record
     * @return
     */
    @Override
    public List<RoleGroupMemberEntity> selectByExample(RoleGroupMemberEntity record) {
        return roleGroupMemberDAO.selectByExample(this.getExamle(record));
    }

    @Override
    public List<RoleGroupMemberEntity> selectByExample(RoleGroupMemberEntityExample example) {
        return roleGroupMemberDAO.selectByExample(example);
    }

    /**
     * 获取条件
     * @param record
     * @return
     */
    private RoleGroupMemberEntityExample getExamle(RoleGroupMemberEntity record){
        RoleGroupMemberEntityExample example=new RoleGroupMemberEntityExample();
        RoleGroupMemberEntityExample.Criteria criteria = example.createCriteria();
        if(record.getId() !=null){
            criteria.andIdEqualTo(record.getId());
        }
        if(record.getGroupCode() !=null && record.getGroupCode() !=""){
            criteria.andGroupCodeEqualTo(record.getGroupCode());
        }
        if(record.getRoleCode() !=null && record.getRoleCode() !=""){
            criteria.andRoleCodeEqualTo(record.getRoleCode());
        }
        return example;
    }
}
